package exercise

import (
	"fmt"
	"strings"
)

/*
你有50枚金币，需要分配给以下几个人：Matthew,Sarah,Augustus,Heidi,Emilie,Peter,Giana,Adriano,Aaron,Elizabeth。
分配规则如下：
a. 名字中每包含1个'e'或'E'分1枚金币
b. 名字中每包含1个'i'或'I'分2枚金币
c. 名字中每包含1个'o'或'O'分3枚金币
d: 名字中每包含1个'u'或'U'分4枚金币
写一个程序，计算每个用户分到多少金币，以及最后剩余多少金币？
程序结构如下，请实现 ‘dispatchCoin’ 函数
*/
var (
	coins = 50
	users = []string{
		"Matthew", "Sarah", "Augustus", "Heidi", "Emilie", "Peter", "Giana", "Adriano", "Aaron", "Elizabeth",
	}
	distribution = make(map[string]int, len(users))
)

func DispatchCoin() {
	rule := map[string]int{
		"e": 1,
		"i": 2,
		"o": 3,
		"u": 4,
	}
	var count int
	for _, user := range users {
		var userCount int
		for _, word := range user {
			lowerWords := strings.ToLower(string(word))
			num, ok := rule[lowerWords]
			if ok {
				userCount += num
			}
		}
		distribution[user] = userCount
		count += userCount
	}
	fmt.Printf("剩余硬币 (coins - count): %v\n", (coins - count))
	fmt.Printf("分发的硬币 count: %v\n", count)
	fmt.Printf("每个人的硬币数 distribution: %v\n", distribution)
}
